/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.uha.ensisa.kfetmanager.category;

import fr.uha.ensisa.kfetmanager.customer.Customer;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author JC
 */
@Entity
public class CustomerCategory implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String label;

    @OneToMany(mappedBy = "category")
    private List<Customer> customers;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public List<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }

    public Iterator<Customer> iterator() {
        return this.getCustomers().iterator();
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof CustomerCategory)) {
            return false;
        }
        CustomerCategory other = (CustomerCategory) object;
        return other.getLabel().equals(this.getLabel());
    }

    @Override
    public String toString() {
        return label;
    }

}
